//
// Copyright 2010-2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License").
// You may not use this file except in compliance with the License.
// A copy of the License is located at
//
// http://aws.amazon.com/apache2.0
//
// or in the "license" file accompanying this file. This file is distributed
// on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
// express or implied. See the License for the specific language governing
// permissions and limitations under the License.
//

import XCTest

@testable import AWSTranscribeStreaming

class AWSSRWebSocketDelegateAdaptorDidOpenTests: XCTestCase {

    /// - Given: An adaptor with a delegate
    /// - When: The adaptor receives `-[webSocketDidOpen:]` invocation
    /// - Then: the delegate receives a connectionDidChange
    func testAdaptor() {
        let delegate = MockTranscribeStreamingClientDelegate()
        let receivedStatusCallback = expectation(description: "Received status callback")

        delegate.connectionStatusCallback = { status, error in
            if let error = error {
                XCTFail("Unexpected error in testConnectionDidChangeErrorIsNilForCleanlyClosed: \(error)")
                return
            }
            XCTAssertEqual(status, AWSTranscribeStreamingClientConnectionStatus.connected)
            receivedStatusCallback.fulfill()
        }

        let adaptor = AWSSRWebSocketDelegateAdaptor(clientDelegate: delegate, callbackQueue: DispatchQueue.global())

        adaptor.webSocketDidOpen(nil)

        waitForExpectations(timeout: 0.1)
    }

}
